<?php
class Ynbusinesspages_Form_Business_Create extends Engine_Form
{
	protected $_formArgs;
	
	public function getFormArgs()
	{
		return $this -> _formArgs;
	}
	
	public function setFormArgs($formArgs)
	{
		$this -> _formArgs = $formArgs;
	} 
	
  public function init()
  {
	$view = Zend_Registry::get('Zend_View');
    $settings = Engine_Api::_()->getApi('settings', 'core');
    $id = Engine_Api::_()->user()->getViewer() -> level_id;

    $this->setTitle('Create New Company');
	
	//Category
	 $this->addElement('Select', 'category_id', array(
	  'required'  => true,
      'allowEmpty'=> false,
      'label' => '*Category',
    ));
	
	 // add more category
    $this->addElement('Cancel', 'add_more_category', array(
        'label' => 'Add more', 
        'link' => true,
        'ignore' => true,
        'onclick' => 'javascript:void(0)'
    ));
	
	//Company name
    $this->addElement('Text', 'name', array(
      'label' => '*Business Name',
      'allowEmpty' => false,
      'required' => true,
      'validators' => array(
        array('NotEmpty', true),
      ),
      'filters' => array(
        'StripTags',
        new Engine_Filter_Censor(),
      ),
    ));
	
	//Short description
	$this->addElement('Textarea', 'short_description', array(
        'label' => '*Short Description',
        'allowEmpty' => false,
      	'required' => true,
        'filters' => array(
            'StripTags',
        ),
        'validators' => array(
	        array('NotEmpty', true),
	        array('StringLength', false, array(1, 300)),
		),
    ));
	
	$allowed_html = 'strong, b, em, i, u, strike, sub, sup, p, div, pre, address, h1, h2, h3, h4, h5, h6, span, ol, li, ul, a, img, embed, br, hr, object , param, iframe';
	
	$editorOptions['plugins'] = array(
        'table', 'fullscreen', 'media', 'preview', 'paste',
        'code', 'image', 'textcolor', 'link'
      );

	  $editorOptions['toolbar1'] = array(
	    'undo', 'redo', 'removeformat', 'pastetext', '|', 'code',
	    'media', 'image', 'link', 'fullscreen',
	    'preview'
	  );
	  
	//Description
    $this->addElement('TinyMce', 'description', array(
      'label' => 'Description',
      'editorOptions' => $editorOptions,
      'filters' => array(
        new Engine_Filter_Censor(),
        new Engine_Filter_Html(array('AllowedTags'=>$allowed_html)))
    ));
	
	//Search Result
	$this->addElement('Radio', 'search', array(
      'label' => 'Include in search results?',
      'multiOptions' => array(
        '1' => 'Yes, include in search results.',
        '0' => 'No, hide from search results.',
      ),
      'value' => '1',
    ));
	
	//Adress map
	$this -> addElement('Dummy', 'location_map', array(
		'description' => 'Full Address',
		'decorators' => array( array(
			'ViewScript',
			array(
				'viewScript' => '_location_search.tpl',
				'class' => 'form element',
				'label' => 'Headquarter',
			)
		)), 
	));
		
	$this -> addElement('hidden', 'location_address', array(
		'value' => '0',
		'order' => '97'
	));

	$this -> addElement('hidden', 'lat', array(
		'value' => '0',
		'order' => '98'
	));
	
	$this -> addElement('hidden', 'long', array(
		'value' => '0',
		'order' => '99'
	));
	
	//Approve member
	$this->addElement('Radio', 'approval', array(
      'label' => 'Approve members?',
      'description' => ' When people try to join this business, should they be allowed '.
        'to join immediately, or should they be forced to wait for approval?',
      'multiOptions' => array(
        '0' => 'New members can join immediately.',
        '1' => 'New members must be approved.',
      ),
      'value' => '0',
    ));
	
	//Custom field
    if( !$this->_item ) {
      $customFields = new Ynjobposting_Form_Company_Fields(array_merge(array(
        'labelField' => 'field',
      	),$this -> _formArgs));
	}
    if( get_class($this) == 'Ynjobposting_Form_Company_Create' ) {
      $customFields->setIsCreation(true);
    }
	
    $this->addSubForms(array(
      'fields' => $customFields
    ));
	
	//Contact Information
	$this ->addElement('heading', 'contact_info', array(
		'label' => 'Contact Information',
	));
	
	//Phone
	$this->addElement('Text', 'phone', array(
        'label' => 'Phone',
        'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
    
	//Fax
	$this->addElement('Text', 'fax', array(
        'label' => 'Fax',
        'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	//Email
    $this->addElement('Text', 'email', array(
        'label' => '*Email',
        'allowEmpty' => false,
     	'required' => true,
     	'validators' => array(
	        array('NotEmpty', true),
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
    
	//City
    $this->addElement('Text', 'city', array(
        'label' => 'City',
     	'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	//Province
    $this->addElement('Text', 'province', array(
        'label' => 'Province',
     	'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	//Zip Code
	$this->addElement('Integer', 'zip_code', array(
        'label' => 'Zip Code',
        'validators' => array(
            new Engine_Validate_AtLeast(1),
        ),
    ));
	
	//Web address
	$this->addElement('Text', 'web_address', array(
        'label' => 'Web Address',
     	'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	// Logo
	$this->addElement('File', 'photo', array(
      'label' => 'Logo',
    ));
    $this->photo->addValidator('Extension', false, 'jpg,png,gif,jpeg');
	
	//Facebook
	$this->addElement('Text', 'facebook', array(
        'label' => 'Facebook',
     	'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	//Twitter
	$this->addElement('Text', 'twitter', array(
        'label' => 'Twitter',
     	'validators' => array(
	        array('StringLength', false, array(1, 64)),
		),
	    'filters' => array(
	        'StripTags',
	        new Engine_Filter_Censor(),
	    ),
    ));
	
	//Additional Information
	$this -> addElement('Dummy', 'addmore', array(
		'decorators' => array( array(
			'ViewScript',
			array(
				'viewScript' => '_add_info.tpl',
				'class' => 'form element',
			)
		)), 
	));
	
	$this->addElement('Text', 'number_add_more', array(
      'style' => 'display:none;',
      'value' => 1,
    ));
	

    // Buttons
    $this->addElement('Button', 'submit_button', array(
      'value' => 'submit_button',
      'label' => 'Create',
      'onclick' => 'removeSubmit()',
      'type' => 'submit',
      'ignore' => true,
      'decorators' => array(
        'ViewHelper',
      ),
    ));
	
    $this->addElement('Cancel', 'cancel', array(
      'label' => 'cancel',
      'link' => true,
      'prependText' => ' or ',
      'decorators' => array(
        'ViewHelper',
      ),
    ));

    $this->addDisplayGroup(array('submit_button', 'cancel'), 'buttons', array(
      'decorators' => array(
        'FormElements',
        'DivDivDivWrapper',
      ),
    ));
  }
}
